//
//  BGWebController.m
//  bigMall
//
//  Created by ios on 16/9/29.
//  Copyright © 2016年 thinklev. All rights reserved.
//

#import "BGWebController.h"
#import "MBProgressHUD.h"
#import "MBProgressHUD+MJ.h"

@interface BGWebController ()<UIWebViewDelegate>

@end

@implementation BGWebController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [[UIApplication sharedApplication].keyWindow setBackgroundColor:[UIColor whiteColor]];
    
    self.title = @"详情";
    
    [self createUI];
    
}
- (void)createUI {
    
    [MBProgressHUD showMessage:@"加载中..."];
    
    UIWebView *web = [[UIWebView alloc] initWithFrame:self.view.bounds];
    web.backgroundColor = [UIColor clearColor];
    web.opaque = NO;
    web.delegate = self;
    [web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.url]]];
    [self.view addSubview:web];
    
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
    [MBProgressHUD hideHUD];
    NSLog(@"%@", [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.innerHTML"]);
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    [MBProgressHUD showError:@"加载失败了!!!"];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)viewWillAppear:(BOOL)animated {
    self.tabBarController.tabBar.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated {
    self.tabBarController.tabBar.hidden = NO;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSMutableURLRequest *mutableRequest = [request mutableCopy];
    
    NSString *sendParam = [[NSString alloc] initWithData:mutableRequest.HTTPBody encoding:NSUTF8StringEncoding];
    
    if(![sendParam isEqualToString:@""]){
        
        //        NSString *newData = [sendParam MD5Value];
        
        //        NSUInteger length = [newData length];
        NSString *length = [[NSUserDefaults standardUserDefaults] objectForKey:sessionId];
        [mutableRequest addValue:[NSString stringWithFormat:@"%@...",length] forHTTPHeaderField:@"PHPSESSID"];
        
        request = [mutableRequest copy];
        
    }else{
        
        return YES;
    }
    
    [webView loadRequest:request];
    
    return YES;
}
@end
